# app/controllers/family/family_system.py
from typing import List, Optional

from app.services.family.family_system import family_service
from app.schemas.family.family_system import FamilyCreate, FamilyUpdate
# 
from app.models import Family
from app.core.crud import CRUDBase


class FamilyController():
    """家庭控制器"""
    async def get_family_tree(self, name: Optional[str] = None):
        """获取家庭树结构"""
        return await family_service.get_family_tree(name)

    async def get_family_info(self, family_id: int):
        """获取家庭详细信息"""
        return await family_service.get_family_info(family_id)

    async def create_family(self, obj_in: FamilyCreate, creator_id: int):
        """创建家庭"""
        return await family_service.create_family(obj_in, creator_id)

    async def update_family(self, obj_in: FamilyUpdate):
        """更新家庭信息"""
        return await family_service.update_family(obj_in)

    async def delete_family(self, family_id: int):
        """删除家庭"""
        return await family_service.delete_family(family_id)

    async def add_family_member(self, family_id: int, user_id: int, nickname: str = None, is_admin: bool = False):
        """添加家庭成员"""
        return await family_service.add_family_member(family_id, user_id, nickname, is_admin)

    async def remove_family_member(self, family_id: int, user_id: int):
        """移除家庭成员"""
        return await family_service.remove_family_member(family_id, user_id)

    async def get_user_families(self, user_id: int):
        """获取用户所属的所有家庭"""
        return await family_service.get_user_families(user_id)

    async def get_family_members(self, family_id: int):
        """获取家庭的所有成员"""
        return await family_service.get_family_members(family_id)


family_controller = FamilyController()